﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

using PacketAnalyzer.Data;

namespace PacketAnalyzer.Analyzer
{
    public class PacketDataFactory
    {
        static Regex rx = new Regex("()*[0-9]{5}[^\t^\r^\n^\\]]+");              

        public static List<PacketData> Analyze(string packet) 
        {
            IAnalyzer analyzer = null;            

            if (packet.Contains("TCHODR") || packet.Contains("TTRTDP") || packet.Contains("TTRODP"))
            {
                analyzer = ZomojoAnalyzer.GetInstance();
            }
            else
            {
                if (rx.IsMatch(packet))
                {
                    packet = rx.Match(packet).Value;
                }
                else
                    return null;

                analyzer = ZentecAnalyzer.GetInstance();
            }

            List<PacketData> packetDataList = analyzer.Analyze(packet);

            return packetDataList;
        }
    }
}
